<!DOCTYPE HTML>
<html>
<head>
    <title>Todo</title>
    <link rel="stylesheet" href="/stylesheets/style.css">
    <script src="/scripts/jquery.min.js"></script>
    <link rel="stylesheet" href="/scripts/miniui/themes/default/miniui.css">
    <link rel="stylesheet" href="/scripts/miniui/themes/icons.css">
    <link rel="stylesheet" href="/scripts/miniui/themes/bootstrap/skin.css">
    <link rel="stylesheet" href="/editor/common.css">
    <script src="/scripts/miniui/miniui.js"></script>
</head>
<body  style="padding: 0;width: 100%;height: 100%">
<div class="mini-splitter" style="width:100%;height:100%;">
    <div size="240" showCollapseButton="true">
        <div class="mini-fit">
            <ul id="tree1" class="mini-tree"  url="/json/accountTree.json" style="width:100%;"
                showTreeIcon="true" textField="name" idField="id" onnodeclick="onNodeDblClick" parentField="pid" resultAsTree="false"
            >
            </ul>
        </div>
    </div>
    <div showCollapseButton="true">
        <div id="outImg">
            <img id="imgId" src="" alt="" onclick="smallImg()">
        </div>
        <div style="padding: 5px">
            <span>用户id：</span><input  class="mini-textbox" type="text" id="userOId"/>
            <span>用户昵称：</span><input  class="mini-textbox" type="text" id="nickName"/>
            <a class="mini-button" iconCls="icon-search" onclick="search()">查找</a>
        </div>
        <div style="width:99%;">
            <div class="mini-toolbar" style="border-bottom:0;padding:0;">
                <table style="width:100%;">
                    <tr>
                        <td style="width:100%;">
                            <!--<a class="mini-button" iconCls="icon-add" onclick="shopMangerAdd()">增加</a>-->
                            <a id="refund" style="display: none" class="mini-button" iconCls="icon-edit" onclick="shopMangerEdit()">编辑</a>
                            <a id="receipt" style="display: none" class="mini-button" iconCls="icon-add" onclick="receipt()">确认收货</a>
                            <a id="sendGoods" style="display: none" class="mini-button" iconCls="icon-add" onclick="send()">发货</a>
                            <!--<a class="mini-button" iconCls="icon-remove" onclick="shopMangerRemove()">删除</a>-->
                        </td>
                    </tr>
                </table>
            </div>
        </div>

        <div id="datagrid1" class="mini-datagrid" style="width:99%;height: 82%;"
             url="/getdata/accountOrder" idField="id" allowResize="true"
             sizeList="[20,30,50,100]" pageSize="30"
             onshowrowdetail="onShowRowDetail"
        >
            <div property="columns">
                <div type="expandcolumn" >#</div>
                <div field="userOId" width="120" headerAlign="center" allowSort="true">用户id
                    <input property="editor" class="mini-textbox" />
                </div>
                <div field="status" width="50" allowSort="true" renderer="statusRenderer" align="center" headerAlign="center">冻结状态</div>
                <div field="nickName" width="80" align="center" headerAlign="center" allowSort="true">昵称</div>
                <div field="userAvatar" width="50" allowSort="true"  align="center" headerAlign="center">头像</div>
                <div field="remark" width="80" allowSort="true" renderer="picRenderer" align="center" headerAlign="center">收益类型</div>
                <div field="refund" width="80" allowSort="true" renderer="refundRenderer" align="center" headerAlign="center">是否退款</div>
                <div field="changeType" width="80" allowSort="true" renderer="changeRenderer" align="center" headerAlign="center">变动类型</div>
                <div field="changeMoney" width="100" align="center" headerAlign="center" allowSort="true">金额</div>
                <div field="objectId" width="100" align="center" headerAlign="center" allowSort="true">objectId</div>
                <div field="createdAt" width="100" align="center" headerAlign="center"  allowSort="true">创建日期</div>
                <div field="updatedAt" width="100" align="center" headerAlign="center" allowSort="true">更新日期</div>
            </div>
        </div>
        <div id="editForm1" style="display:none;">
            <div  class="mini-tabs" style="width:100%;" activeIndex="0">
                <div id="editForm2" title="交易来源">
                    <input class="mini-hidden" name="id"/>
                    <table style="width:100%;">
                        <tr style="height: 50px">
                            <td style="width: 80px;">来源：</td>
                            <td style="width:150px;"><input id="buyerNickName" class="mini-textbox" ></td>
                            <td style="width:50px;">头像：</td>
                            <td style="width: 100px"><div id="buyerAvatar" style="width: 100px"></div></td>
                            <td style="width:80px;">订单总额：</td>
                            <td style="width:150px;"><input id="changeMoney" class="mini-textbox" ></td>
                            <td style="width:80px;">订单编号：</td>
                            <td style="width:150px;"><input id="orderNo" class="mini-textbox" ></td>
                        </tr>
                        <tr style="height: 50px" >
                            <td style="width: 80px;">部落Id：</td>
                            <td style="width:150px;"><input id="tribeId" class="mini-textbox" ></td>
                            <td style="width: 80px;">部落名称：</td>
                            <td style="width:150px;"><input id="tribeName" class="mini-textbox" ></td>
                        </tr>

                    </table>
                </div>
                <div title="收益来源">
                    <input class="mini-hidden"/>
                    <table style="width:100%;">
                        <tr style="height: 50px">
                            <td style="width:80px;">购买数量：</td>
                            <td style="width:150px;"><input name="goodsNum" class="mini-textbox" /></td>
                            <td style="width:80px;">购买规格：</td>
                            <td style="width:150px;"><input name="goodsModel" class="mini-textbox" /></td>
                            <td style="width: 80px;">商品价格：</td>
                            <td style="width: 150px"><input name="price"  class="mini-textbox" /></td>
                            <td style="width: 80px;">商品名称：</td>
                            <td style="width:80px;"><input name="goodsName" class="mini-textbox" style="width: 300px"/></td>
                        </tr>
                        <tr style="height: 50px" >
                            <td style="width:80px;">团购价格：</td>
                            <td><input name="groupPrice" class="mini-textbox" /></td>
                            <td style="width:80px;">商品图片</td>
                            <td><div id="picArr"></div></td>
                        </tr>

                    </table>

                </div>
                <div title="分享用户信息">
                    <div id="datagrid2" class="mini-datagrid" style="width:99%;height: 200px;"
                         url="/getdata/relateGoodsInformation" idField="id" allowResize="true"
                         sizeList="[20,30,50,100]" pageSize="10"
                    >
                        <div property="columns">
                            <div type="checkcolumn" ></div>
                            <div field="userOId" width="120" headerAlign="center" allowSort="true" >用户Id</div>
                            <div field="nickName" width="80" align="left" headerAlign="center" allowSort="true" >用户昵称</div>
                            <div field="userAvatar"  width="70" align="center" headerAlign="center" renderer="onGenderRenderer" allowSort="true" >用户头像</div>
                        </div>
                    </div>
                </div>
            </div>
            <div style="text-align:right;padding-top:5px;padding-right:20px;" colspan="6">
                <a class="Update_Button" href="javascript:updateRow();">提交</a>
                <a class="Cancel_Button" href="javascript:cancelRow();">取消</a>
            </div>
        </div>
    </div>
</div>
</body>
<script type="text/javascript">
    var userStatus = [{ id: 1, text: '审核成功' }, { id: 0, text: '未审核'},{ id: 4, text: '审核失败'},{ id: 3, text: '审核中'}];
    var flag = 1;
    mini.parse();
    var editForm = document.getElementById("editForm1");
    var refund = document.getElementById("refund");
    var receipt = document.getElementById("receipt");
    var sendGoods = document.getElementById("sendGoods");
    var tree = mini.get("tree1");
    var grid = mini.get("datagrid1");
    var grid2 = mini.get("datagrid2");

    function onNodeDblClick(e) {
        var userOId = mini.get("userOId").getValue();
        var nickName = mini.get("nickName").getValue();

        grid.load({
            remark: e.node.id,
            userOId: userOId,
            nickName: nickName,
        });
    };
    grid.load();
    grid.on("drawcell", function (e) {
        var  value = e.value;
        column = e.column;
//        row = e.row;
        //将性别文本替换成图片
        if (column.field == "userAvatar") {
            if(value) {
                e.cellHtml = '<img class="bigImg" onclick="bigImg()" src="' + value + '?imageMogr2/thumbnail/640x/format/jpg/interlace/1/auto" width="30" height="30" alt="图片">';
            }else{
                e.cellHtml = '<img class="bigImg" onclick="bigImg()"  src="http://7xiuo5.com1.z0.glb.clouddn.com/fgImage.png?imageMogr2/auto-orient/thumbnail/!100x100r/gravity/Center/crop/100x100/quality/80/auto-orient" width="30" height="30" alt="图片">';
            }
        }
    });

    grid2.on("drawcell", function (e) {
        var  value = e.value;
        column = e.column;
//        row = e.row;
        //将性别文本替换成图片
        if (column.field == "userAvatar") {
            if(value) {
                e.cellHtml = '<img class="bigImg" onclick="bigImgTwo()" src="' + value + '?imageMogr2/thumbnail/640x/format/jpg/interlace/1/auto" width="30" height="30" alt="图片">';
            }else{
                e.cellHtml = '<img class="bigImg" onclick="bigImgTwo()"  src="http://7xiuo5.com1.z0.glb.clouddn.com/fgImage.png?imageMogr2/auto-orient/thumbnail/!100x100r/gravity/Center/crop/100x100/quality/80/auto-orient" width="30" height="30" alt="图片">';
            }
        }
    });

    function search() {
        var userOId = mini.get("userOId").getValue();
        var nickName = mini.get("nickName").getValue();
        grid.load({
            userOId: userOId,
            nickName:nickName,
        });
    }
    function searchStatus() {
        var status = mini.get("status").getValue();
        grid.load({
            status: status
        });
    }
    $("#userOId,#nickName").bind("keydown", function (e) {
        if (e.keyCode == 13) {
            search();
        }
    });


    function shopMangerEdit() {
        var row = grid.getSelected();
        if (row) {
            mini.open({
                url: "getdata/updateOrder/refund?id="+row.objectId,
                title: "退款信息信息", width: 600, height: 400,

                ondestroy: function (action) {

                    grid.reload();

                }
            });

        } else {
            alert("请选中一条记录");
        }

    }
    function receipt() {
        var row = grid.getSelected();
        if (row) {
            $.ajax({
                url:"/getdata/updateOrder/updateStatus",
                type:'POST',
                data:{
                    objectId:row.objectId,
                    status:5
                },
                success:function (result) {
                    grid.reload();
                }
            });
        } else {
            alert("请选中一条记录");
        }

    }
    function send() {
        var row = grid.getSelected();
        if (row) {
            mini.open({
                url: "getdata/updateOrder/send?id="+row.objectId,
                title: "发货信息信息", width: 600, height: 400,

                ondestroy: function (action) {

                    grid.reload();

                }
            });

        } else {
            alert("请选中一条记录");
        }

    }
    function shopMangerAdd() {
        mini.open({
            url: "/getdata/shopMangerAdd",
            title: "编辑用户信息", width: 600, height: 400,

            ondestroy: function (action) {

                grid.reload();

            }
        });
    }
    function shopMangerRemove() {
        var row = grid.getSelected();
        if (row) {
            $.ajax({
                url:"/getdata/updataShopInformation",
                type:'POST',
                data:{
                    objectId:row.objectId,
                    status:0
                },
                success:function (result) {
                    grid.reload();
                }
            });
        } else {
            alert("请选中一条记录");
        }

    }

    function bigImg() {
        var row = grid.getSelected();
        if (row) {
            var path = row.userAvatar;
            $("#imgId").attr('src', path);
            $("#outImg").css('display','block');
        }
    }
    function bigImgTwo() {
        var row = grid2.getSelected();
        if (row) {
            var path = row.userAvatar;
            $("#imgId").attr('src', path);
            $("#outImg").css('display','block');
        }
    }
    function smallImg() {
        $("#outImg").css('display','none');
    }


    function onBirthdayRenderer(e) {
        var value = e.value;
        if (value) return mini.formatDate(value, 'yyyy-MM-dd hh:mm:ss');
        return "";
    }
    function statusRenderer(e) {
        var value = e.value;
        if (value==1) {
            return (value,'正常')
        }else if(value==0) {
            return (value, '冻结')
        }
    };

    function changeRenderer(e) {
        var value = e.value;
        if (value==1) {
            return (value, '收入')
        }else if(value==2){
            return (value, '支出')
        }else if(value==3){
            return (value, '提现')
        }
    }
    function refundRenderer(e) {
        var value = e.value;
        if (value==1) {
            return (value, '退款')
        }else {
            return (value,'正常')
        }
    }

    function onShowRowDetail(e) {
        var grid = e.sender;
        var row = e.record;

        //将editForm元素，加入行详细单元格内
        var td = grid.getRowDetailCellEl(row);
        td.appendChild(editForm);
        editForm.style.display = "";

        //加载
        var form = new mini.Form("editForm1");
        if (grid.isNewRow(row)||row.orderNo==""||row.orderNo==null) {
            $("#buyerAvatar").empty();
            $("#picArr").empty();
            form.reset();
        } else {
            form.reset();
            $("#buyerAvatar").empty();
            $("#picArr").empty();
            $.ajax({
                url: "/getdata/getIncomSource?orderCode=" + row.orderNo+"&userOId="+row.userOId+"&objectId="+row.objectId,
                success: function (text) {
                    var o = mini.decode(text);
                    if (o.result!=undefined){
                        if(o.result.shareUser!=""&&o.result.shareUser!=null){
                            grid2.setData(o.result.shareUser.data);
                            grid2.setTotalCount(o.result.shareUser.count);
                        }else{
                            grid2.setData();
                            grid2.setTotalCount();
                        }
                        mini.get("buyerNickName").setValue(o.result.tradeSource.nickName);
                        mini.get("changeMoney").setValue(o.result.accountDetail.changeMoney);
                        mini.get("orderNo").setValue(o.result.tradeSource.orderNo);
                        mini.getByName("goodsNum").setValue(o.result.orderGoodsInfo.num);
                        mini.getByName("goodsModel").setValue(o.result.orderGoodsInfo.goodsModel);
                        mini.getByName("price").setValue(o.result.orderGoodsInfo.price);
                        mini.getByName("goodsName").setValue(o.result.orderGoodsInfo.goodsName);
                        mini.get("tribeId").setValue(o.result.tradeSource.tribeId);
                        mini.get("tribeName").setValue(o.result.tradeSource.tribeName);
                        $("#buyerAvatar").append('<img class="bigImg" style="width: 75px;height: 75px" src='+o.result.tradeSource.userAvatar+' />');
                        $("#picArr").append('<img class="bigImg" style="width: 75px;height: 75px" src='+o.result.orderGoodsInfo.goodsPicURL+' />');
                        grid.unmask();
                    }else{
                        form.reset();
                    }

                },
                error:function (result) {
                    alert("未知错误")
                }
            });
        }
    }
    function cancelRow() {
        grid.reload();
    }

    function updateRow() {
        var form = new mini.Form("editForm1");
        var o = form.getData();
//        grid.loading("保存中，请稍后......");
        var json = mini.encode(o);
        grid.reload();
    }
</script>
</html>